 <link rel="stylesheet" type="text/css" href="{{base_url()}}data/jscripts/loto/css/dt.bootstrap.css">
<script type="text/javascript" src="{{base_url()}}data/jscripts/loto/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="{{base_url()}}data/jscripts/loto/js/dt.bootstrap.js"></script>
<div id="history">
<form action="" method="get">       
 <table style="margin:0px auto;width:95%">
    <tr>
        <td>Từ ngày:</td>
        <td>Đến ngày:</td>
        <td>Tài khoản:</td>
        <td>Vật phẩm:</td>
        <td>Trạng thái:</td>
        <td>Nhóm theo:</td>
        <td></td>
    </tr>
    <tr>
        <td>
            <select name="datefrom">
                <option value=""></option>
                {{foreach $loto_reward->get_list_date() as $k=>$date_item}}
                    <option value="{{$k}}" {{if $_input['datefrom']==$k}}selected="selected"{{/if}}>{{$date_item}}</option>
                {{/foreach}}
            </select>
        </td>
        <td>
            <select name="dateto">
                <option value=""></option>
                {{foreach $loto_reward->get_list_date() as $k=>$date_item}}
                    <option value="{{$k}}" {{if $_input['dateto']==$k}}selected="selected"{{/if}}>{{$date_item}}</option>
                {{/foreach}}
            </select>
        </td>
        <td>
            <select name="username">
                 <option value="">Tất cả</option>
                {{foreach $loto_customer->get_list() as $k=>$item}}
                    <option value="{{$item}}" {{if $_input['username']==$item}}selected="selected"{{/if}}>{{$item}}</option>
                {{/foreach}}
            </select>
        </td>
        <td>
            <select name="item">
                 <option value="">Tất cả</option>
                {{foreach $loto_item->get_list_item() as $k=>$item}}
                    <option value="{{$k}}" {{if $_input['item']==$k}}selected="selected"{{/if}}>{{$item}}</option>
                {{/foreach}}
            </select>
        </td>
        <td>    
            <select name="status">
                 <option value="">Tất cả</option>
                 <option value="0" {{if $_input['status']=="0"}}selected="selected"{{/if}}>Chưa xử lý</option>
                 <option value="1" {{if $_input['status']=="1"}}selected="selected"{{/if}}>Đã xử lý</option>
            </select>
        </td>
        <td>
            <select name="group_by">
                <option value=""></option>
                <option value="loto_item_id"  {{if $_input['group_by']=='loto_item_id'}}selected="selected"{{/if}}>Vật phẩm</option>
            </select>
        </td>
        <td>
            <input type="submit" value="XEM"/>
            <a href ="{{base_url()}}auth/loto/export"> Xuất Excel</a>
        </td>
    </tr>
</table>
</form>
<p></p>
{{*$loto_reward->history_backend($_input['datefrom'], $_input['dateto'], $_input['item'])|@print_r*}}    
<table class="table table-striped table-bordered table-hover" id="history_table" style="width:90%;margin:0px auto;">
<thead>
    <tr>
        <th width="10%" class="center">STT</th>
        <th width="20%">Tài khoản</th> 
        <th width="25%">Email</th>
        <th width="30%">Tên vật phẩm</th> 
        <th width="15%">Số lượng</th> 
        <!--  th width="10%" class="center">Trạng thái <!--input type="checkbox" name="status" value="" onclick="check_all(this)"/--></th>
    </tr>
<thead>
<tbody>
    {{foreach $loto_reward->history_backend($_input) as $k=>$item}}  
        <tr> 
                <td class="center"><strong>{{$k+1}}</strong></td>                      
                <td class="center">{{if ($_input['group_by']=="")}}{{$item->loto_customer_username}}{{/if}}</td> 
                <td class="center">{{if ($_input['group_by']=="")}}{{$loto_customer->email_by_name($item->loto_customer_username)}}{{/if}}</td>  
                <td class="center">{{$item->loto_item_name}}</td> 
                <td class="center">{{$item->total}}</td> 
                <!--  td class="center"><input id="{{$item->id}}" type="checkbox" name="status" value="" {{if $item->status}}checked="checked"{{/if}} onclick="change_status(this)"/></td>  
            	-->
            </tr>
    {{/foreach}}
</tbody>
</table>
</div>
<script type="text/javascript">
    function change_status(tag_name){
        // alert($(tag_name).attr("checked"));
         
         if($(tag_name).attr("checked")){
            status = 1;
         }else{
            status = 0;
         }
         //alert(status);
         ajax_update_status($(tag_name).attr("id"), status);
    }
    
    function check_all(tag_name){
        //alert($(tag_name).attr("checked"));
        if($(tag_name).attr("checked")=="checked"){
            $("input[name=status]").each(function(){
                $(this).attr("checked", "checked");
                ajax_update_status($(this).attr("id"), 1);
            });
        }else{
            $("input[name=status]").each(function(){
                $(this).removeAttr("checked");
                ajax_update_status($(this).attr("id"), 0);
            });
        }   
    }
    function ajax_update_status(_id, _status){
        $.ajax({
              url: "{{base_url()}}auth/loto/update_status",
              type: "POST",
              data: {id : _id, status : _status},
              async: true,
              success: function(data) {}
        });

    }    
$(function(){
    //{{if $_input['group_by']==""}}
     //   $("input[type=submit]").click();
    //{{/if}}
    
    //state_dateto();
    
    //$("select[name=datefrom]").change(function(){
    //    state_dateto();
   // });
})

function  state_dateto(){
        if($("select[name=datefrom]").val()==""){
            $("span#dateto").hide();
            $("select[name=dateto]").hide();
        }else{
            $("span#dateto").show();
            $("select[name=dateto]").show();
        }
}
</script>
<style type="text/css">
.center {
    text-align: center !important;
}
#history {
    color: black;
    font-family: Arial;
    font-size: 14px;
    line-height: 1;
}
</style>